package com.gt.andr.multbl;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;

/**
 * onClick Listener
 * 
 * @author Ganesh
 * 
 */
public class MultiplicationTableButtonClickListener implements OnClickListener {

	EditText valueField;
	boolean isIncreaseBtn;

	/**
	 * 
	 * @param valueField, the original input field
	 * @param isIncreaseBtn
	 */
	public MultiplicationTableButtonClickListener(EditText valueField, boolean isIncreaseBtn) {
		this.valueField = valueField;
		this.isIncreaseBtn = isIncreaseBtn;
	}

	@Override
	public void onClick(View v) {
		String strVal = valueField.getText().toString().trim();
		int intVal = 0;
		if (!strVal.isEmpty()) {
			intVal = Integer.parseInt(strVal);
		}
		// change value
		if (isIncreaseBtn) {
			valueField.setText(String.valueOf(++intVal));
		} else {
			valueField.setText(String.valueOf(--intVal));
		}
	}

}
